package com.atguigu.guli.service.edu.api;


import com.atguigu.guli.service.base.dto.CourseDto;
import com.atguigu.guli.service.base.result.R;
import com.atguigu.guli.service.edu.entity.Course;
import com.atguigu.guli.service.edu.entity.query.WebCourseQuery;
import com.atguigu.guli.service.edu.entity.vo.ChapterVo;
import com.atguigu.guli.service.edu.entity.vo.WebCourseVo;
import com.atguigu.guli.service.edu.service.ChapterService;
import com.atguigu.guli.service.edu.service.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2020-10-14
 */
@RestController

@Api(tags = "课程管理")
@RequestMapping("/api/edu/course")
public class ApiCourseController {
    @Autowired(required = true)
    private CourseService courseService;

    @Autowired(required = true)
    private ChapterService chapterService;

    @ApiOperation("根据ID查询课程信息")
    @GetMapping("get-course-dto/{courseId}")
    public R getCourseDtoById(@PathVariable String courseId){
        CourseDto courseDto = courseService.getCourseDtoById(courseId);
        return R.ok().data("courseDto",courseDto);
    }


    @ApiOperation("课程列表")
    @GetMapping("list")
    public R courseList(WebCourseQuery webCourseQuery){

        System.out.println(webCourseQuery);
        List<Course> courseList = courseService.courseList(webCourseQuery);
        return R.ok().data("courseList",courseList);
    }


    @ApiOperation("课程信息")
    @GetMapping("/get/{courseId}")
    public R courseInfo(@PathVariable String courseId){
        WebCourseVo webCourseVo = courseService.selectWebCourseVoById(courseId);

        //查询当前课程的章节信息
        List<ChapterVo> chapterVoList = chapterService.nestedListByCourseId(courseId);
        return R.ok().data("course", webCourseVo).data("chapterVoList", chapterVoList);
    }
}

